@@ -68,7 +68,7 @@ module Agents |
||
| 68 | 68 |
|
| 69 | 69 |
If you want to retain original contents of events and only add new keys, then set `mode` to `merge`, otherwise set it to `clean`. |
| 70 | 70 |
|
| 71 |
- By default, the output event will have `agent` and `created_at` fields added as well, reflecting the original Agent type and Event creation time. You can skip these outputs by setting `skip_agent` and `skip_created_at` to `true`. |
|
| 71 |
+ By default, the output event will have `created_at` fields added as well, reflecting the original Event creation time. You can skip this output by setting `skip_created_at` to `true`. |
|
| 72 | 72 |
|
| 73 | 73 |
To CGI escape output (for example when creating a link), use the Liquid `uri_escape` filter, like so: |
| 74 | 74 |
|
@@ -82,7 +82,7 @@ module Agents |
||
| 82 | 82 |
after_save :clear_matchers |
| 83 | 83 |
|
| 84 | 84 |
def validate_options |
| 85 |
- errors.add(:base, "instructions, mode, skip_agent, and skip_created_at all need to be present.") unless options['instructions'].present? && options['mode'].present? && options['skip_agent'].present? && options['skip_created_at'].present? |
|
| 85 |
+ errors.add(:base, "instructions, mode, and skip_created_at all need to be present.") unless options['instructions'].present? && options['mode'].present? && options['skip_created_at'].present? |
|
| 86 | 86 |
|
| 87 | 87 |
validate_matchers |
| 88 | 88 |
end |
@@ -91,11 +91,11 @@ module Agents |
||
| 91 | 91 |
{
|
| 92 | 92 |
'instructions' => {
|
| 93 | 93 |
'message' => "You received a text {{text}} from {{fields.from}}",
|
| 94 |
+ 'agent' => "{{agent.type}}",
|
|
| 94 | 95 |
'some_other_field' => "Looks like the weather is going to be {{fields.weather}}"
|
| 95 | 96 |
}, |
| 96 | 97 |
'matchers' => [], |
| 97 | 98 |
'mode' => "clean", |
| 98 |
- 'skip_agent' => "false", |
|
| 99 | 99 |
'skip_created_at' => "false" |
| 100 | 100 |
} |
| 101 | 101 |
end |
@@ -111,7 +111,6 @@ module Agents |
||
| 111 | 111 |
opts = interpolated(payload) |
| 112 | 112 |
formatted_event = opts['mode'].to_s == "merge" ? event.payload.dup : {}
|
| 113 | 113 |
formatted_event.merge! opts['instructions'] |
| 114 |
- formatted_event['agent'] = agent.short_type unless opts['skip_agent'].to_s == "true" |
|
| 115 | 114 |
formatted_event['created_at'] = event.created_at unless opts['skip_created_at'].to_s == "true" |
| 116 | 115 |
create_event :payload => formatted_event |
| 117 | 116 |
end |
@@ -0,0 +1,21 @@ |
||
| 1 |
+class ConvertEfaSkipAgent < ActiveRecord::Migration |
|
| 2 |
+ def up |
|
| 3 |
+ Agent.where(type: 'Agents::EventFormattingAgent').each do |agent| |
|
| 4 |
+ agent.options_will_change! |
|
| 5 |
+ unless agent.options.delete('skip_agent').to_s == 'true'
|
|
| 6 |
+ agent.options['instructions'] = {
|
|
| 7 |
+ 'agent' => '{{agent.type}}'
|
|
| 8 |
+ }.update(agent.options['instructions'] || {})
|
|
| 9 |
+ end |
|
| 10 |
+ agent.save! |
|
| 11 |
+ end |
|
| 12 |
+ end |
|
| 13 |
+ |
|
| 14 |
+ def down |
|
| 15 |
+ Agent.where(type: 'Agents::EventFormattingAgent').each do |agent| |
|
| 16 |
+ agent.options_will_change! |
|
| 17 |
+ agent.options['skip_agent'] = (agent.options['instructions'] || {})['agent'] == '{{agent.type}}'
|
|
| 18 |
+ agent.save! |
|
| 19 |
+ end |
|
| 20 |
+ end |
|
| 21 |
+end |